<?php
/**
 *
 * 功能说明：权限规则模型。
 *
 **/
namespace Home\Model;
use Common\Model\BaseModel;

class AuthGroupAccessModel extends BaseModel{

	/**
	 * 根据group_id获取全部用户id
	 * @param  int $group_id 用户组id
	 * @return array         用户数组
	 */
	public function getUidsByGroupId($group_id){
		$user_ids=$this
			->where(array('group_id'=>$group_id))
			->getField('uid',true);
		return $user_ids;
	}

	/**
	 * 获取管理员权限列表
	 */
	public function getAllData($map){
		$data['count'] = D('User')->where($where)->count();			//总记录数
		$url='/statics/image/Home/';
		$Page = new \Think\Page($data['count'],3);				//实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('header','共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页');
		$Page->setConfig('prev','<img src="'.$url.'prev.gif" border="0" title="上一页" />');
		$Page->setConfig('next','<img src="'.$url.'next.gif" border="0" title="下一页" />');
		$Page->setConfig('first','<img src="'.$url.'first.gif" border="0" title="第一页" />');
		$Page->setConfig('last','<img src="'.$url.'last.gif" border="0" title="最后一页" />');
		$Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');//显示的先后顺序
        $Page->lastSuffix = false;//最后一页不显示为总页数
		$data['show'] = $Page->show();							//分页显示输出
		

		$data['volist']=$this
			->field('u.id,u.username,u.email,aga.group_id,group_concat(ag.title SEPARATOR "、") as title,d.title as department')
			->alias('aga')
			->join('__USER__ u ON aga.uid=u.id','RIGHT')
			->join('__AUTH_GROUP__ ag ON aga.group_id=ag.id','LEFT')
			->join('__DEPARTMENT__ d ON u.departmentid=d.id')//这里如果用左右连接是查不到的
			->where($map)
			->group('id')
			->limit($Page->firstRow.','.$Page->listRows)
			->select();

		return $data;

	}


}
